<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <title>表格测试</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta charset="utf-8">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css" media="all" charset="utf-8">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/style.css">
    <script src="${pageContext.request.contextPath}/layui/js/jquery-1.11.1.min.js"></script>
    <script src="${pageContext.request.contextPath}/layui/layui.all.js"></script>
    <script src="${pageContext.request.contextPath}/layui/lay/modules/layer.js"></script>
</head>


<body>

<%------------------------------学生列表--------------------------------%>
<%------------------------------学生列表--------------------------------%>
<%------------------------------学生列表--------------------------------%>


<div class="layui-col-md12">
    <div class="layui-main layui-bg-gray">
        <table id="Stulist" lay-filter="stu" class="layui-bg-green" align="center"/>
        <script type="text/html" id="barDemo2">
            <a class="layui-btn layui-btn-radius layui-btn-xs" lay-event="xuanke" id="xuanke">选课</a>
            <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="chakebiao" id="chakebiao">查看课表</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete" id="delete">删除</a>
        </script>
    </div>


    <script>
        var $ = null;
        layui.use(["jquery", "upload", "form", "table", "layer", "element", "laydate"], function () {
            $ = layui.jquery;
            var element = layui.element,
                layer = layui.layer,
                upload = layui.upload,
                form = layui.form,
                laydate = layui.laydate,
                table = layui.table;
            //记录选中的数据:做缓存使用,作为参数传递给后台,然后生成pdf ,压缩
            var ids = new Array();
            //当前表格中的全部数据:在表格的checkbox全选的时候没有得到数据, 因此用全局存放变量

            table.render({
                elem: "#Stulist",
                totalRow: true,
                skin: 'line', //行边框风格
                url: "${pageContext.request.contextPath}/ss/stuList.html",
                page: true, //开启分页
                request: {
                    /* pageName: 'page' //页码的参数名称，默认：page
                     , limitName: 'size' //每页数据量的参数名，默认：limit*/
                }
                   , response: {
                     statusName: 'code' //数据状态的字段名称，默认：code
                    , statusCode: 0 //成功的状态码，默认：0
                    , msgName: 'msg' //状态信息的字段名称，默认：msg
                    , countName: 'totalCount' //数据总数的字段名称，默认：count
                    , dataName: 'data' //数据列表的字段名称，默认：data
                }
                ,
                cols: [[

                    {field: "id", title: 'ID', align: 'center', width: 130},
                    {field: "ID", title: '学号', align: 'center', width: 130},
                    {
                        field: "StuName",
                        width: 130,
                        title: "姓名",
                        align: "center"
                    }, {
                        field: "StuAge",
                        width: 130,
                        title: "年龄",
                        align: "center"
                    }, {
                        field: "bjgrade",
                        width: 130,
                        title: "年级",
                        align: "center"
                    }, {
                        field: "bjname",
                        width: 130,
                        title: "班级",
                        align: "center",
                    }, {
                        title: "操作",
                        width: 282,
                        align: "center",
                        toolbar: "#barDemo2",
                    }]]
                , id: 'courseTable',
                done: function (res, curr, count) {
                    $("[data-field='id']").remove();
                },
                limit: 10,
            });

            table.on("tool(stu)", function (obj) {
               var data = obj.data;


                if (obj.event === 'xuanke') {

                    //方法一
                    /*$.ajax({

                        type: "get",
                        url: "${pageContext.request.contextPath}/ss/getId.html",
                        data:{
                            data:data.ID
                        },
                        dataType : "json",
                        contentType: "application/json",
                        success: function (data) {

                            var url="${pageContext.request.contextPath}"+data.url;
                            layer.open({
                                type: 2,
                                title: "选课",
                                closeBtn: 1, //不显示关闭按钮
                                shade: 0.8,
                                max: false,
                                move: false,
                                resize: false,
                                shadeClose: true,
                                area: ['900px', '500px'],
                                offset: '50px', //右下角弹出
                                content: [url], //iframe的url，no代表不显示滚动条
                            });
                        }
                    });*/

                    //方法二
                    var url="${pageContext.request.contextPath}/ss/xuankefrom.html?suid="+data.ID
                    console.log(url)
                    layer.open({
                        type: 2,
                        title: "选课",
                        closeBtn: 1, //不显示关闭按钮
                        shade: 0.8,
                        max: false,
                        move: false,
                        resize: false,
                        shadeClose: true,
                        area: ['900px', '500px'],
                        offset: '50px', //右下角弹出
                        content: [url], //iframe的url，no代表不显示滚动条
                    });


                } else if (obj.event === "chakebiao") {
                    console.log(data)
                    var data = obj.data;
                    var stuid = data.ID;
                    var stuname = data.StuName;
                    console.log(stuname)
                    $.ajax({
                        type: "get",
                        url: "${pageContext.request.contextPath}/ss/stuCheckCou.html?stuid=" + stuid,
                        contentType: "application/json",
                        success: function (data) {
                            alert("你选的课是")
                        }
                    });


                } else if (obj.event === "delete") {
                    var data = obj.data;
                    var couname = $('#searContent').val();//得到输入框的值
                    console.log(couname)
                    var stuid = data.stuid;
                    var stuname = data.stuname;


                }
                element.init();
            });
        });



    </script>
</div>
</body>
</html>
